﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Caching;
using Telerik.Web.UI;
using System.Data.Common;
using System.Data;
using System.Web.Services;
using System.Text;
using java.util;

public partial class _Default : System.Web.UI.Page
{
    private Cache cache = HttpContext.Current.Cache;
    Control mainControl;

   

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["ProvinceID"] == null)
            {
                Response.Redirect("~/", false);
            }
            else
            {
                string str = Session["ProvinceID"].ToString();
            }
        }
    }

    private HashMap setUserControl()
    {
        HashMap hm = new HashMap();
        hm.put("trang-chu", "~/Components/Home.ascx");
        hm.put("", "~/Components/Home.ascx");
        hm.put("san-pham-moi", "~/Components/Home.ascx");
        hm.put("san-pham-ua-chuong", "~/Components/Home.ascx");
        hm.put("gioi-thieu", "~/Components/About.ascx");
        hm.put("san-pham", "~/Components/Product.ascx");
        hm.put("he-thong-cua-hang", "~/Components/Shop.ascx");
        hm.put("su-kien", "~/Components/News.ascx");
        hm.put("khuyen-mai", "~/Components/News.ascx");
        hm.put("cam-nang", "~/Components/News.ascx");
        hm.put("tin-tuc-chi-tiet", "~/Components/NewsDetail.ascx");
        hm.put("tu-van-qua-dien-thoai", "~/Components/AdvicePhone.ascx");
        hm.put("gop-y", "~/Components/Feedback.ascx");
        hm.put("chi-tiet-san-pham", "~/Components/ProductDetail.ascx");
        hm.put("tim-kiem-san-pham", "~/Components/Search.ascx");
        hm.put("don-dat-hang", "~/Components/SaleOrder.ascx");
        hm.put("san-pham-qua-tang", "~/Components/PromotionProduct.ascx");
        hm.put("dat-hang-thanh-cong", "~/Components/PaymentSuccess.ascx");
        hm.put("tuyen-du", "~/Components/AboutCompany.ascx");
       
        return hm;
    }

    private HashMap setUserControlRight()
    {
        HashMap hm = new HashMap();
        hm.put("trang-chu", "1");
        hm.put("", "1");
        hm.put("san-pham-moi", "1");
        hm.put("san-pham-ua-chuong", "1");
        hm.put("gioi-thieu", "0");
        hm.put("san-pham", "1");
        hm.put("he-thong-cua-hang", "0");
        hm.put("su-kien", "1");
        hm.put("khuyen-mai", "1");
        hm.put("cam-nang", "1");
        hm.put("tin-tuc-chi-tiet", "1");
        hm.put("tu-van-qua-dien-thoai", "0");
        hm.put("gop-y", "0");
        hm.put("chi-tiet-san-pham", "1");
        hm.put("tim-kiem-san-pham", "1");
        hm.put("don-dat-hang", "0");
        hm.put("san-pham-qua-tang", "0");
        hm.put("dat-hang-thanh-cong", "0");
        hm.put("tuyen-du", "0");
        return hm;
    }
    protected void Page_Init(object sender, EventArgs e)
    {
        string funcName = string.Empty;
        string param = string.Empty;
        string username = string.Empty;
        string userControl = "~/Components/Home.ascx";
        try
        {
            HashMap hm = setUserControl();
            
            string FunctionName = "";
            if (Page.RouteData.Values["FunctionName"] == null)//vua load vao
            {
                userControl = "~/Components/Home.ascx";
            }
            else if (Page.RouteData.Values["FunctionName"].ToString().ToLower() == "default.aspx")
            {
                userControl = "~/Components/Home.ascx";
            }
            else//Click menu
            {
                FunctionName = Server.HtmlEncode(Page.RouteData.Values["FunctionName"].ToString());
                if (hm.get(FunctionName) != null)
                {
                    userControl = hm.get(FunctionName.ToLower()).ToString();
                }
                else
                {
                    userControl = "~/Components/Home.ascx";
                }
            }
            //~/Components/Home.ascx
            string url = ResolveUrl(userControl);
            mainControl = LoadControl(url);
            phContentLeft.Controls.Add(mainControl);
            //Page.Title = function.FunctionName;

            HashMap hm1 = setUserControlRight();
            if (Page.RouteData.Values["FunctionName"] == null)
            {
                // Right
                url = ResolveUrl("~/Components/Right.ascx");
                mainControl = LoadControl(url);
                phContentRight.Controls.Add(mainControl);
            }
            else
            {
                FunctionName = Server.HtmlEncode(Page.RouteData.Values["FunctionName"].ToString());
                if (hm1.get(FunctionName) == null || hm1.get(FunctionName).ToString() == "1")
                {
                    // Right
                    url = ResolveUrl("~/Components/Right.ascx");
                    mainControl = LoadControl(url);
                    phContentRight.Controls.Add(mainControl);
                }
            }
        }
        catch (Exception ex)
        {
            userControl = "~/Components/Home.ascx";
        }
    } 
}